
from aop.aop_config import load_global_config
from aop.aop_timeit import timeit
from services.base_dev_common_service import BaseDevCommonService


class SyncZAfterAllSynced(BaseDevCommonService):
    @load_global_config('../config/config.json5')
    def __init__(self, model_class=None, time_field=None):
        super().__init__(model_class, time_field)


@timeit(name="SyncZAfterAllSynced")
def update():
    after_all_synced = SyncZAfterAllSynced(model_class=None)
    sql = """
    UPDATE op_order_tb  t1 join  op_order_goods_tb  t2  on t1.tid = t2.tid  and t1.`created` >= DATE_SUB(CURDATE(), INTERVAL 10 DAY) AND t1.`created` < CURDATE()
  SET t2.op_order_tb_id = t1.id;
    """
    res = after_all_synced.execute_native_sql(sql)
    print('update', res)

def select():
    after_all_synced = SyncZAfterAllSynced(model_class=None)
    sql = """
SELECT count(*)
FROM op_order_tb t1
         join op_order_goods_tb t2
              on t2.op_order_tb_id = t1.id and t1.`created` >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND
                 t1.`created` < CURDATE();
      """
    res = after_all_synced.execute_native_sql(sql)
    print('select',res)

if __name__ == '__main__':
    # select()
    update()
